from django.contrib import admin
from info_sys.models import Supplier, Buyer, Item, Order, OrderItem, goodItem, goodVerfiyImage
# Register your models here.
class ItemAdmin(admin.ModelAdmin):
    list_display = ('id', 'name', 'sup_type', 'created')

class OrderItemInline(admin.StackedInline):
    # 内联表
    model = OrderItem
    fields = ['item', 'count']
    extra = 0

class OrderAdmin(admin.ModelAdmin):
    # 日期选择栏
    date_hierarchy = 'created'
    list_editable = ['is_verify']  # 列表直接修改
    list_display = ('id','buyer', 'is_verify', 'content_plus','created')
    # fieldsets = [
    #     ('基本信息', {'fields': ['buyer', 'content', 'is_verify']}),
    # ]
    def get_form(self, request, obj=None, **args):
        defaults = {}
        self.inlines = [OrderItemInline]

        defaults.update(args)
        return super(OrderAdmin, self).get_form(request, obj, **defaults)

class OrderItemAdmin(admin.ModelAdmin):
    list_display = ('id', 'order', 'item', 'count')

class SupplierItemAdmin(admin.ModelAdmin):
    list_display = ('id', 'phone', 'zone', 'is_verify')

class BuyerItemAdmin(admin.ModelAdmin):
    list_display = ('id', 'phone', 'zone', 'is_verify')


class GoodsImgInline(admin.StackedInline):
    # 内联表
    model = goodVerfiyImage
    fields = ['name', 'my_img', 'is_verify', 'is_deleted']
    extra = 0

class GoodItemAdmin(admin.ModelAdmin):
    # 日期选择栏
    date_hierarchy = 'created'
    list_editable = ['is_verify']  # 列表直接修改
    list_display = ('id','supplier', 'sup_type', 'is_verify', 'content_plus','created')
    # fieldsets = [
    #     ('基本信息', {'fields': ['supplier', 'content', 'is_verify']}),
    # ]
    def get_form(self, request, obj=None, **args):
        defaults = {}
        self.inlines = [GoodsImgInline]
        defaults.update(args)
        return super(GoodItemAdmin, self).get_form(request, obj, **defaults)

class GoodImgAdmin(admin.ModelAdmin):
    list_display = ('id', 'name', 'is_verify', 'is_deleted')

admin.site.register(Item, ItemAdmin)
admin.site.register(Order, OrderAdmin)
admin.site.register(OrderItem, OrderItemAdmin)
admin.site.register(Supplier, SupplierItemAdmin)
admin.site.register(Buyer, BuyerItemAdmin)
admin.site.register(goodItem, GoodItemAdmin)
admin.site.register(goodVerfiyImage, GoodImgAdmin)